package cn.sirun.com.fca.account.uitl;

import android.text.TextUtils;

import com.tencent.cloud.iov.util.storage.TXSharedPreferencesUtils;

import cn.sirun.com.fca.account.constant.CarConst;
import cn.sirun.com.fca.account.model.base.CarInfoDetailResponse;

/**
 * @author vinsonhuang
 * @date 2018/10/10
 */
public class CurCarInfoUtils {

    public static void saveCarInfo(CarInfoDetailResponse carInfo) {
        if (null != carInfo) {
            TXSharedPreferencesUtils.setValue(CarConst.SpKey.CUR_CAR_INFO,
                    GsonHelper.getGson().toJson(carInfo));
        } else {
            TXSharedPreferencesUtils.remove(CarConst.SpKey.CUR_CAR_INFO);
        }
    }

    public static CarInfoDetailResponse getCarInfo() {
        String carInfoString = TXSharedPreferencesUtils.getValue(
                CarConst.SpKey.CUR_CAR_INFO);
        if (TextUtils.isEmpty(carInfoString)) {
            return null;
        }
        return GsonHelper.getGson().fromJson(carInfoString, CarInfoDetailResponse.class);
    }

}
